package com.cmccgz.baselibrary.view;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.cmccgz.baselibrary.R;


/**
 * @author
 * @date 2017/3/15 16:45
 */

public class DefaultProgressDialog extends AlertDialog {
    private int layoutId;
    private LayoutInflater inflater = null;

    public DefaultProgressDialog(Context context, int themeId, int layoutId) {
        super(context, themeId);
        this.layoutId = layoutId;
        inflater = LayoutInflater.from(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View v = inflater.inflate(layoutId, null);// 得到加载view
        RelativeLayout layout = (RelativeLayout) v.findViewById(R.id.dialog_view);// 加载布局
        ImageView iv_loading = (ImageView) v.findViewById(R.id.iv_loading);
        AnimationDrawable animationDrawable = (AnimationDrawable) iv_loading.getBackground();
        animationDrawable.start();
        setContentView(layout);
        /** 设置透明度 */
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.alpha = 1f;// 透明度
        lp.dimAmount = 0f;// 黑暗度
        window.setAttributes(lp);
        window.getDecorView().setBackgroundResource(android.R.color.transparent);
    }

}
